from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from .routers import auth, workouts, routines

from .database import Base, engine

app = FastAPI()

Base.metadata.create_all(bind=engine)

origins = [
    # 指定允许访问后端的前端的地址
    "http://localhost:3000",
    "http://127.0.0.1:3000",
    # Add more origins here
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"]
)
app.include_router(auth.router)
app.include_router(workouts.router)
app.include_router(routines.router)


@app.get("/")
async def root():
    return {"message": "Hello World"}


@app.get("/hello/{name}")
async def say_hello(name: str):
    return {"message": f"Hello {name}"}
